#include <cstdio>
#include <queue>
using namespace std;

int n;
typedef long long int llt;
llt t, a, b, tmp, sum;

int main(void) {
  while (scanf("%d", &n) == 1) {
    priority_queue<llt, vector<llt>, greater<llt> > pq;
    int i;
    for(i = 0; i < n; i++) {
      scanf("%lld", &t);
      pq.push(t);
    }
    
    sum = 0;
    while(pq.size() > 1) {
      a = pq.top();
      pq.pop();
      b = pq.top();
      pq.pop();
      tmp = a + b;
      sum += tmp;
      pq.push(tmp);
    }
    
    printf("%lld\n", sum);
  }
  return 0;
}